package com.ruoyi.project.goods.billHead.service.impl;

import java.util.List;

import com.ruoyi.common.exception.BusinessException;
import com.ruoyi.project.goods.bill.domain.GoodsBill;
import com.ruoyi.project.goods.bill.service.IGoodsBillService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.project.goods.billHead.mapper.GoodsBillHeadMapper;
import com.ruoyi.project.goods.billHead.domain.GoodsBillHead;
import com.ruoyi.project.goods.billHead.service.IGoodsBillHeadService;
import com.ruoyi.common.utils.text.Convert;

/**
 * 发货单明细Service业务层处理
 * 
 * @author lonsn
 * @date 2021-05-19
 */
@Service
public class GoodsBillHeadServiceImpl implements IGoodsBillHeadService 
{
    @Autowired
    private GoodsBillHeadMapper goodsBillHeadMapper;
    @Autowired
    private IGoodsBillService billService;

    /**
     * 查询发货单明细
     * 
     * @param billHeadId 发货单明细ID
     * @return 发货单明细
     */
    @Override
    public GoodsBillHead selectGoodsBillHeadById(Long billHeadId)
    {
        return goodsBillHeadMapper.selectGoodsBillHeadById(billHeadId);
    }

    /**
     * 查询发货单明细列表
     * 
     * @param goodsBillHead 发货单明细
     * @return 发货单明细
     */
    @Override
    public List<GoodsBillHead> selectGoodsBillHeadList(GoodsBillHead goodsBillHead)
    {
        return goodsBillHeadMapper.selectGoodsBillHeadList(goodsBillHead);
    }

    /**
     * 新增发货单明细
     * 
     * @param goodsBillHead 发货单明细
     * @return 结果
     */
    @Override
    public int insertGoodsBillHead(GoodsBillHead goodsBillHead)
    {
        //检查发货单状态
        GoodsBill bill= billService.selectGoodsBillById(goodsBillHead.getBillNo());
        if(bill!=null){
            if(bill.getStatus()!=1 && bill.getStatus()!=null){
                throw new BusinessException("只有新建状态发货单才可增加商品");
            }
        }
        return goodsBillHeadMapper.insertGoodsBillHead(goodsBillHead);
    }

    /**
     * 修改发货单明细
     * 
     * @param goodsBillHead 发货单明细
     * @return 结果
     */
    @Override
    public int updateGoodsBillHead(GoodsBillHead goodsBillHead)
    {
        return goodsBillHeadMapper.updateGoodsBillHead(goodsBillHead);
    }

    /**
     * 删除发货单明细对象
     * 
     * @param ids 需要删除的数据ID
     * @return 结果
     */
    @Override
    public int deleteGoodsBillHeadByIds(String ids)
    {
        return goodsBillHeadMapper.deleteGoodsBillHeadByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除发货单明细信息
     * 
     * @param billHeadId 发货单明细ID
     * @return 结果
     */
    @Override
    public int deleteGoodsBillHeadById(Long billHeadId)
    {
        return goodsBillHeadMapper.deleteGoodsBillHeadById(billHeadId);
    }
}
